const log4js = require('log4js')

const urlString = 'https://www.baidu.com/abc/efg?name=10&age=100#sex'
// 解析传递的url字符串为url对象
const url = new URL(urlString)
// console.log(url)
// 从url对象中获取指定query参数的值
// console.log(url.searchParams.get('name'))
// console.log(url.searchParams.get('age'))

// 使用log4js记录该日志
// 1.创建log规则
log4js.configure({
  appenders: {cheese: {type: 'file', filename: 'cheese.log'}},
  categories: {default: {appenders: ['cheese'], level: 'error'}},
})
// 2.创建一个logger，指定配置中的某个logger配置
const logger = log4js.getLogger('cheese')
// 3.指定日志的类别
logger.level = 'debug'

// 4.使用logger
logger.log('url:', url)
logger.log('urlSearchParams:name => ', url.searchParams.get('name'))
logger.log('urlSearchParams:age => ', url.searchParams.get('age'))
